﻿@model thailandProject.Models.CLIENT

@{
    ViewBag.Title = "Edit Client";
}

<div id="Wrapper2">
    <div id="content_header">
        <div id="headerimage">
        </div>
        <div id="theheader">@ViewBag.Header</div>
    </div>
    <!-- Left Column begins here -->
    <aside id="sidebar-wrapper">
        <nav class="sidebar">
            <!-- CONTENT GOES HERE -->

    @using (Html.BeginForm("EditClient", "Clients", FormMethod.Post, new { id = "editForm" }))
            {
    @Html.ValidationSummary(true)

        <div class="editor-label">
            <label for="firstname">First Name</label>
        </div>
        <div class="editor-field">
            <input type="hidden" name="clientID" value="@Model.clientID" />
            <input type="text" id="clientFirstName" name="clientFirstName" maxlength="50" value="@Model.clientFirstName" />
        </div>
        <div id="clientFirstNameError" style="color:red; visibility:hidden;">First name must not be empty</div>

        <div class="editor-label">
            <label for="lastname">Last Name</label>
        </div>
        <div class="editor-field">
            <input type="text" name="clientLastName" maxlength="50" value="@Model.clientLastName" />
        </div>

        <div class="editor-label">
            <label for="email">Email</label>
        </div>
        <div class="editor-field">
            <input type="text" id="clientEmail" name="clientEmail" maxlength="50" value="@Model.clientEmail" />
        </div>
        <div id="clientEmailError" style="color:red; visibility:hidden;">Email must not be empty</div>

        <div class="editor-label">
            <label for="address">Address</label>
        </div>
        <div class="editor-field">
            <input type="text" name="clientAddress" maxlength="50" value="@Model.clientAddress" />
        </div>

        <div class="editor-label">
            <label for="city">City</label>
        </div>
        <div class="editor-field">
            <input type="text" name="clientCity" maxlength="50" value="@Model.clientCity" />
        </div>

        <div class="editor-label">
            <label for="city">State/Providence</label>
        </div>
        <div class="editor-field">
            <input type="text" name="clientStateProvidence" maxlength="50" value="@Model.clientStateProvidence" />
        </div>

        <div class="editor-label">
            <label for="passport">Passport No.</label>
        </div>
        <div class="editor-field">
            <input type="text" name="clientPassportNum" maxlength="10" value="@Model.clientPassportNum" />
        </div>

        <div class="editor-label">
            <label for="notes">Memo</label>
        </div>
        <div class="editor-field">
            <textarea id="clientNotes" name="clientNotes">@Model.clientNotes</textarea>
            <span id="charsLeft">&nbsp;</span>
        </div>
        
        <p style="float:left; width:100%;">
            <input type="image" src="../../images/save_button.png" value="Save" />
            <span id="formError" style="color:red; visibility:hidden">Please correct the above errors to continue</span>
            <input type="hidden" id="formcheck" value="false" />
        </p>

            }

<p>
    @Html.ActionLink("Back", "ViewClient", new { clientId = Model.clientID })
</p>

            
        </nav>
    </aside>
    <!-- Right column begins here -->
    <article id="contents">
        
    </article>
    <!-- Right column ends here -->
</div>
<!-- Div wrapper2 ends here -->

<script>
    $("#editForm").submit(function () {
        //Make sure the first name and email fields are not empty
        var isValid = true;

        if ($("#clientFirstName").val() == "") {
            $("#clientFirstNameError").attr('style', 'color:red; visibility:visible;');
            isValid = false;
            $("#clientFirstName").focus();
        }
        else
            $("#clientFirstNameError").attr('style', 'color:red; visibility:hidden;');

        if ($("#clientEmail").val() == "") {
            $("#clientEmailError").attr('style', 'color:red; visibility:visible;');
            if (isValid)
                $("#clientEmail").focus();

            isValid = false;
        }
        else
            $("#clientEmailError").attr('style', 'color:red; visibility:hidden;');

        if (isValid) {
            $("#formError").attr('style', 'color:red; visibility:hidden;');
            if ($("#formcheck").val() == 'false') {
                $("#formcheck").val('true');
                return true;
            }
            else {
                alert('Your action is currently being processed. Please wait');
                return false;
            }
        }
        else {
            $("#formError").attr('style', 'color:red; visibility:visible;');
            return false;
        }
    })

    $("#clientNotes").keyup(function () {
        var message = $(this).val();

        if (message.length > 2000) {
            message = message.substr(0, 2000);
            $(this).val(message);
        }

        $("#charsLeft").text(2000 - message.length + " chars left");
    })
</script>